package com.xiang.community.config;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;

import java.time.Duration;

/**
 * @author qixiangLi
 * @Date 2021/12/22
 */
@Configuration
public class ElasticSearchConfig {
    @Value("${elasticsearch.host.one:localhost:9200}")
    private String hostOne;

    @Bean
    RestHighLevelClient client() {
        ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                .connectedTo(hostOne)
                .withConnectTimeout(Duration.ofSeconds(5))
                .withConnectTimeout(Duration.ofSeconds(3))
                .build();
        return RestClients.create(clientConfiguration).rest();
    }
}
